package com.block.source.service;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.block.common.model.vo.ResultInfoVO;
import com.block.common.service.LogFactory;
import com.block.db.entity.SourceBaseInfo;
import com.block.source.model.dto.SourceApiParam;
import com.block.source.model.dto.SourceApiResult;
import com.block.test.reqbean.source.CheckUserInfo;
import org.slf4j.Logger;

import java.sql.Struct;
import java.util.Map;

public abstract class ISourceReceiveService {

    private static final Logger log = LogFactory.getSourceLog();

    public abstract SourceApiResult handleCheckUserData(SourceBaseInfo sourceBaseInfo, Map<String, String[]> parameterMap, String paramContent);

    public abstract SourceApiResult handleRegisterUserData(SourceBaseInfo sourceBaseInfo, Map<String, String[]> parameterMap, String paramContent);

    public abstract SourceApiResult getCheckUserReturnData(SourceBaseInfo sourceBaseInfo, ResultInfoVO resultInfoVO, SourceApiParam sourceApiParam);

    public abstract SourceApiResult getRegisterUserReturnData(SourceBaseInfo sourceBaseInfo, ResultInfoVO resultInfoVO, SourceApiParam sourceApiParam);

    public abstract JSONObject getError(String message);

    public abstract JSONObject getSuccess();

    /**
     * 定制化
     */
    public abstract JSONObject resultInit(String channelCode, String reqId, String action);

    public abstract JSONObject getError(JSONObject resultObj, String errCode, String errMsg);

    public abstract JSONObject getError(JSONObject resultObj, String errMsg);

    public abstract JSONObject getSuccess(JSONObject resultObj, JSONObject dataObj);


    public abstract SourceApiResult getCheckUserReturnData(SourceBaseInfo sourceBaseInfo, ResultInfoVO resultInfoVO, SourceApiParam sourceApiParam, String mobileMd5);


    // 撞库参数校验
    public static String verifyCheckUserParam(CheckUserInfo checkUserInfo){

        if (StrUtil.isEmpty(checkUserInfo.getCityCode())){
            return "城市信息为空/不支持；city:" + checkUserInfo.getCity();
        }
        if (StrUtil.isEmpty(checkUserInfo.getOutOrderNo())){
            return "你方订单号为空";
        }

        Integer age = Integer.valueOf(checkUserInfo.getAge());
        if (age < 23 || age > 55){
            return "年龄范围需要在23-55";
        }

        if (StrUtil.isEmpty(checkUserInfo.getMobileMd5())){
            return "手机号md5值为空";
        }

        if (StrUtil.isEmpty(checkUserInfo.getUserIp())){
            return "用户ip为空";
        }
        if (StrUtil.isEmpty(checkUserInfo.getRealName())){
            // return "用户姓名为空";
            checkUserInfo.setRealName("保密");
        }

        // 判断资质信息是否有空值
        if (ObjectUtil.hasEmpty(
                checkUserInfo.getLoanAmount(), checkUserInfo.getLoanTime(), checkUserInfo.getZhimaScore(),
                checkUserInfo.getGjj(), checkUserInfo.getSalary(),

                checkUserInfo.getHouse(),checkUserInfo.getJob(),checkUserInfo.getCar()
                ,  checkUserInfo.getXueli(), checkUserInfo.getPurpose(),checkUserInfo.getYuqi()
                , checkUserInfo.getEnterpriseOwner()

                , checkUserInfo.getShebao(), checkUserInfo.getBaodan()
        )){
            String format = StrUtil.format("【资质信息】" +
                            "【loanAmount】{}【loanTime】{}【zhimaScore】{}【gjj】{}【salary】{}" +
                            "【house】{}【car】{}【job】{}" +
                            "【xueli】{}【purpose】{}【yuqi】{}【enterpriseOwner】{}" +
                            "【shebao】{}【baodan】{}",

                    checkUserInfo.getLoanAmount(), checkUserInfo.getLoanTime(),
                    checkUserInfo.getZhimaScore(), checkUserInfo.getGjj(), checkUserInfo.getSalary(),

                    checkUserInfo.getHouse(), checkUserInfo.getCar(), checkUserInfo.getJob()
                    , checkUserInfo.getXueli(), checkUserInfo.getPurpose(), checkUserInfo.getYuqi(),
                    checkUserInfo.getEnterpriseOwner(),

                    checkUserInfo.getShebao(), checkUserInfo.getBaodan());
            log.info(format);
            return "资质信息有空值:"+format;
        }

        return null;
    }


}
